/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.dictionary;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

/**
 *
 * @author siarhei
 */
public class EntryEditActivity extends Activity {
    private EditText originalText;
    private EditText translatedText;
    private DictionaryEntry entry;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.entry_edit);

        entry = null;
        originalText = (EditText) findViewById(R.id.original);
        originalText.setHeight(20);
        translatedText = (EditText) findViewById(R.id.translated);
        translatedText.setHeight(20);
        Button confirmButton = (Button) findViewById(R.id.save);        
        
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            Long rowId = extras.getLong(DictionaryEntry._ID);
            entry = DictionaryDao.getInstance(this).get(rowId);

            originalText.setText(entry.getOriginal());
            translatedText.setText(entry.getTranslation());
        } else {
            entry = new DictionaryEntry();
        }

        confirmButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                entry.setOriginal(originalText.getText().toString());
                entry.setTranslation(translatedText.getText().toString());

                DictionaryDao.getInstance(null).save(entry);
                finish();
            }

        });
    }

}
